﻿
Partial Class UCMain_Edit_TP_Request
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If IsNothing(Session("section")) Then
            Session.Clear()
            Response.Redirect("../Login.aspx")
        End If
        If Not IsPostBack Then
            loadData()
        End If
    End Sub

    Sub loadData()
        Dim sql As String = ""
        sql += " SELECT r.ID_REQUEST_FORM,r.DUR_WORK_FORM,r.DUR_WORK_TO "
        sql += " ,Switch(r.WORK_LOCA_W='1','West',r.WORK_LOCA_E='1','East') as work_localW"
        sql += " ,Switch(r.WORK_LOCA_E='1','East')  as work_localE"
        sql += " ,Switch(r.WORK_LOCA_SPECIFY='1','Specify by Statuion',r.WORK_LOCA_SPECIFY='2','Specify by Signal') as SPECIFY"
        sql += " ,Switch(r.WORK_LOCA_SPECIFY='1','from '+(select station+' '+ area from station where id=r.WORK_LOCA_FROM) +' to ' + (select station+' '+ area from station where id=r.WORK_LOCA_To )"
        sql += " ,WORK_LOCA_SPECIFY='2','from ' + (select signal from [signal] where id = r.WORK_LOCA_FROM) +' to ' + (select signal from [signal] where id = r.WORK_LOCA_TO)) as st_si"
        sql += " ,Switch(r.WORK_LOCA_W='1' and WORK_LOCA_E='1' and WORK_LOCA_SPECIFY='2'"
        sql += " ,'from West '+(select station+' '+ area from station where id=r.WORK_LOCA_FROM) +' to ' + (select station+' '+ area from station where id=r.WORK_LOCA_TO)"
        sql += " + ' - from East ' + (select station+' '+ area from station where id=r.WORK_LOCA_FROM_S) +' to ' + (select station+' '+ area from station where id=r.WORK_LOCA_TO_S)"
        sql += "  ) as WE"
        sql += " ,DESC_OD_WORK as desc_work"
        sql += " ,Switch(POWER_REQ='0','Yes') as energ_req"
        sql += " ,Switch(POWER_REQ='0',E1+' '+E2+' '+E3+' '+E4+' '+E5+' '+E6+' '+W1+' '+W2+' '+W3+' '+W4+' '+W5+' '+W6) as energ"
        sql += " ,Switch(TRAIN_REQ='1','Yes',TRAIN_REQ='0','No') as train"
        sql += " ,Switch(VIHECLES_REQ='1','Yes',VIHECLES_REQ='0','No') as vihecle"
        sql += " from Request_table r inner join user_table u "
        sql += " on r.REQ_ID_PICOP = u.ID_USER "
        sql += " where u.[section]='" & Session("section") & "'"
        Dim dt As New Data.DataTable
        dt = clsCommand.SQL_exec(sql)

        GridView1.DataSource = dt
        GridView1.DataBind()

    End Sub

    Protected Sub GridView1_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles GridView1.RowCommand
        Try
            If e.CommandName.ToLower = "bedit" Then
                Response.Redirect("Track_applicationRequest.aspx?ID_REQUEST_FORM=" & e.CommandArgument)
            End If
        Catch ex As Exception

        End Try
    End Sub

    Protected Sub GridView1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged

    End Sub
End Class
